package com.study.services;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.study.model.mdao.EmpwithrightMdao;
import com.study.model.pojo.Empwithright;

@Service
public class EmpwithrightServices {
	@Autowired
	EmpwithrightMdao erm;
	/**
	 * 新增普通员工*/
	public void addEWR(Empwithright e){
		e.setErId(this.getID());
		erm.addEWR(e);
	};
	/**
	 * 经理降职位，普通经理权限，降为员工权限*/
	public void mngrightlower(int eid){
		erm.mngrightlower(eid);
	}
	/**
	 * 根据权限ID查找该权限的人数*/
	public int queryNumbyr(int rid){
		return erm.queryNumbyr(rid);
	}
	public void changeEWR(Map m){
		erm.changeEWR(m);
	}
	/**
	 * 员工删除权限*/
	public void delEWR(int eid){
		erm.delEWR(eid);
	};
	/**
	 * 自动生成ID*/
	public String getID(){
		String maxid=erm.queryMaxid();
		String id="";
		if(maxid != null){
			int num=Integer.parseInt(maxid.substring(2,6));
			if((num+1)/1000!=0){
				id=maxid.substring(0, 2)+(num+1);
			}else if((num+1)/100!=0){
				id=maxid.substring(0, 2)+"0"+(num+1);
			}else if((num+1)/10!=0){
				id=maxid.substring(0, 2)+"00"+(num+1);
			}else{
				id=maxid.substring(0, 2)+"000"+(num+1);
			}
		}else{
			id="er"+"0001";			
		}
		return id;
	}
}
